﻿#pragma execution_character_set("utf-8")
#include "cdatabase.h"
#include <QDebug>
#include <QFileInfo>
#define SSS(R) #R
#define TTT(R) SSS(R)

CDataBase::CDataBase(QObject *parent)
    : QObject(parent)
{
    m_db = QSharedPointer<dbng<sqlite>>(new dbng<sqlite>());

    QString path = TTT(PRO_FILE_PATH);
    path = path + "/src/database/db.db";
    QFileInfo file_info(path);
    if(file_info.exists())
    {
        bool ret = m_db->connect(path.toStdString().c_str());
        if(ret)
        {
            qDebug()<<"数据库连接成功";
        }
    }
}

CDataBase::~CDataBase()
{
    if(!m_db.isNull())
    {
        bool ret = m_db->disconnect();
        ret ? qDebug()<<"关闭数据库" : qDebug()<<"关闭数据库异常";
    }
}

QSharedPointer<dbng<sqlite> > CDataBase::getDB()
{
    return m_db;
}
